// 如果没有通过拦截器配置域名的话，可以在这里写上完整的URL(加上域名部分)
// let hotSearchUrl = '/ebapi/store_api/hot_search';
// let indexUrl = '/ebapi/public_api/index';
// 此处第二个参数vm，就是我们在页面使用的this，你可以通过vm获取vuex等操作，更多内容详见uView对拦截器的介绍部分：
// https://uviewui.com/js/http.html#%E4%BD%95%E8%B0%93%E8%AF%B7%E6%B1%82%E6%8B%A6%E6%88%AA%EF%BC%9F
const baseUrl = 'http://124.93.196.45:10001'
const install = (Vue, vm) => {	
	const author = (header) => {
		console.log(`Login State:${vm.token != ''}`)
		// console.log(vm.token);
		if(vm.token == ''){
			uni.redirectTo({
				url:'/pages/personal/login'
			})
			return;
		}
		return vm.$u.deepMerge(header,{
			Authorization:`Bearer ${vm.token}`
		})
	}
	
	const get_maintenanceAppointmentList = (data) =>{
		return vm.$u.get(baseUrl+'/dev-api/bs-vehicle-owner/maintenance-appointment/page',data,author())
	}
	const get_rechargeList = (data) =>{
		return vm.$u.post(baseUrl+'/dev-api/bs-vehicle-owner/charging-orders/list',data,author())
	}
	const get_mileage =(data) =>{
		return vm.$u.post(baseUrl+'/dev-api/bs-vehicle-owner/vehicle-mileage/list',data,author())
	}
	
	const get_smsCode_unRegister = (data) => vm.$u.get(baseUrl+'/dev-api/sms/captchaNoReg',data);
	const get_smsCode_register =(data)=> vm.$u.get(baseUrl+'/dev-api/sms/captcha',data);
	const post_smsCode_login = (data) => vm.$u.post(baseUrl + '/dev-api/sms/login',data);
	const post_login = (data) => vm.$u.post(baseUrl+ '/dev-api/login',data);
	const post_register = (data) => vm.$u.post(baseUrl+'/dev-api/register',data);
	vm.$u.api = {
		get_maintenanceAppointmentList,
		get_rechargeList,
		get_mileage,
		get_smsCode_unRegister,
		get_smsCode_register,
		post_smsCode_login,
		post_login,
		post_register
	}
	
	
	// 将各个定义的接口名称，统一放进对象挂载到vm.$u.api(因为vm就是this，也即this.$u.api)下
	// vm.$u.api = {getSearch, getInfo};
}

export default {
	install
}